<?php

namespace plugin\cms\app\controller\admin;

use core\controller\AdminBase;
use Exception;
use plugin\cms\app\bll\Comment as BllComment;
use support\View;

class Comment extends AdminBase
{
    public function index()
    {
        $bllComment = new BllComment();
        $comments = $bllComment->paginate(
            contentid: request()->input('contentid', 0),
            cid: request()->input('cid', 0),
            siteid: request()->nowsiteid,
            pagesize: 10
        );

        foreach ($comments as $key => $comment) {
            $sec_comments = $bllComment->paginate(
                contentid: request()->input('contentid'),
                cid: request()->input('cid'),
                mainid: $comment->id,
                order: 'sort ',
                pagesize: PHP_INT_MAX
            );

            $comments[$key]->sec_comments = $sec_comments;
        }
        View::assign('comments', $comments);

        return $this->view(frame: false);
    }


    public function delete()
    {
        try {
            $bllComment = new BllComment();
            $bllComment->delete(request()->get('id'), request()->nowsiteid);
        } catch (Exception $ex) {
            return $this->error($ex->getMessage());
        }
        return $this->success();
    }
}
